//
//  TransMapViewController.m
//  FVQuickMessage
//
//  Created by dllo on 16/8/13.
//  Copyright © 2016年 zty. All rights reserved.
//

#import "TransMapViewController.h"
#import "WalkModel.h"
#import "BusModel.h"
@interface TransMapViewController ()
@property (nonatomic, strong) WalkModel *walkModel;
@property (nonatomic, strong) NSMutableArray <BusModel *> *modelArray;
@property (nonatomic, assign) CGRect rect;
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UILabel *walkLabel;
@property (nonatomic, strong) UIButton *button;
@end

@implementation TransMapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:52 / 255.0 green:51 / 255.0 blue:62 / 255.0 alpha:1];
     _modelArray = [NSMutableArray array];
    [self nscen];
    
    
    
    
}
-(void)change{
    for (NSInteger i = 0; i < _modelArray.count; i++) {
        UILabel *label = [[UILabel alloc] init];
        [self.view addSubview:label];
        BusModel *model = _modelArray[i];
        label.text = [NSString stringWithFormat:@"站点:%@--%@ 途径%ld站 ", model.depart, model.arriva, (unsigned long)model.count];
        label.numberOfLines = 0;
        NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:11]};
        self.rect = [label.text boundingRectWithSize:CGSizeMake(WIDTH * 0.9, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        label.frame = CGRectMake(WIDTH * 0.05, _rect.size.height * i + HEIGHT * 0.05, WIDTH * 0.9, _rect.size.height);
        
        
    }

    //步行
  
    self.walkLabel = [[UILabel alloc] init];
    [self.view addSubview:_walkLabel];
    _walkLabel.frame = CGRectMake(WIDTH * 0.05, _modelArray.count * _rect.size.height + HEIGHT * 0.05, WIDTH, 20);
    //按钮
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:self.button];
    [self.button setTitle:@"我知道了" forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    self.button.frame = CGRectMake(WIDTH * 0.3, _walkLabel.frame.size.height + _modelArray.count * _rect.size.height + HEIGHT * 0.06, WIDTH * 0.4, HEIGHT * 0.1);
    self.button.backgroundColor = [UIColor whiteColor];
    self.button.layer.cornerRadius = 8;
    _walkLabel.text = [NSString stringWithFormat:@"还需步行%ld米, 步行约%ld分", (long)_walkModel.distance, (long)_walkModel.duration / 60];
    
    
}
-(void)buttonAction{
    self.block();
    
}
-(void)setArray:(NSMutableArray *)array{
    _modelArray = array.firstObject;
    _walkModel = array.lastObject;
    [self change];
}


-(void)nscen{
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(move) name:@"move" object:nil];
    
    
}
-(void)move{
     [self.label removeFromSuperview];
    [self.walkLabel removeFromSuperview];
    [self.button removeFromSuperview];
}

@end
